import { onUnmounted } from "vue";

/**
 * IPC事件监听钩子函数
 * @param channel
 * @param listener
 */
export function useIpcListener(channel: string, listener: (...args: any[]) => void) {
  const fn = (_: any, ...args: any[]) => listener(...args);
  ipc.on(channel, fn);

  onUnmounted(() => {
    ipc.off(channel, fn);
  });
}
